{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7f3c0a84",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:30:24.377649Z",
     "start_time": "2022-11-21T12:30:22.816826Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "08264897",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:30:38.167753Z",
     "start_time": "2022-11-21T12:30:38.125865Z"
    }
   },
   "outputs": [],
   "source": [
    "income = pd.read_csv('./dataset/Income1.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "80da5976",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:30:40.745859Z",
     "start_time": "2022-11-21T12:30:40.701973Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>Education</th>\n",
       "      <th>Income</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>26.658839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>10.401338</td>\n",
       "      <td>27.306435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>10.842809</td>\n",
       "      <td>22.132410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>11.244147</td>\n",
       "      <td>21.169841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>11.645485</td>\n",
       "      <td>15.192634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>12.086957</td>\n",
       "      <td>26.398951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>12.488294</td>\n",
       "      <td>17.435307</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>12.889632</td>\n",
       "      <td>25.507885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>13.290970</td>\n",
       "      <td>36.884595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>13.732441</td>\n",
       "      <td>39.666109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>14.133779</td>\n",
       "      <td>34.396281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>14.535117</td>\n",
       "      <td>41.497994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>14.976589</td>\n",
       "      <td>44.981575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>15.377926</td>\n",
       "      <td>47.039595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>15.779264</td>\n",
       "      <td>48.252578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>16.220736</td>\n",
       "      <td>57.034251</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>16.622074</td>\n",
       "      <td>51.490919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>17.023411</td>\n",
       "      <td>61.336621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>17.464883</td>\n",
       "      <td>57.581988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>17.866221</td>\n",
       "      <td>68.553714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>18.267559</td>\n",
       "      <td>64.310925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>18.709030</td>\n",
       "      <td>68.959009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>19.110368</td>\n",
       "      <td>74.614639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>19.511706</td>\n",
       "      <td>71.867195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>19.913043</td>\n",
       "      <td>76.098135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>20.354515</td>\n",
       "      <td>75.775218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>20.755853</td>\n",
       "      <td>72.486055</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>21.157191</td>\n",
       "      <td>77.355021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>21.598662</td>\n",
       "      <td>72.118790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>80.260571</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  Education     Income\n",
       "0            1  10.000000  26.658839\n",
       "1            2  10.401338  27.306435\n",
       "2            3  10.842809  22.132410\n",
       "3            4  11.244147  21.169841\n",
       "4            5  11.645485  15.192634\n",
       "5            6  12.086957  26.398951\n",
       "6            7  12.488294  17.435307\n",
       "7            8  12.889632  25.507885\n",
       "8            9  13.290970  36.884595\n",
       "9           10  13.732441  39.666109\n",
       "10          11  14.133779  34.396281\n",
       "11          12  14.535117  41.497994\n",
       "12          13  14.976589  44.981575\n",
       "13          14  15.377926  47.039595\n",
       "14          15  15.779264  48.252578\n",
       "15          16  16.220736  57.034251\n",
       "16          17  16.622074  51.490919\n",
       "17          18  17.023411  61.336621\n",
       "18          19  17.464883  57.581988\n",
       "19          20  17.866221  68.553714\n",
       "20          21  18.267559  64.310925\n",
       "21          22  18.709030  68.959009\n",
       "22          23  19.110368  74.614639\n",
       "23          24  19.511706  71.867195\n",
       "24          25  19.913043  76.098135\n",
       "25          26  20.354515  75.775218\n",
       "26          27  20.755853  72.486055\n",
       "27          28  21.157191  77.355021\n",
       "28          29  21.598662  72.118790\n",
       "29          30  22.000000  80.260571"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "income"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f8f77550",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:32:05.580872Z",
     "start_time": "2022-11-21T12:32:05.374425Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Income')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAXq0lEQVR4nO3de7BdZXnH8e9PLuWAyCEQYzghPREkjBpJ4EixUYtchLZK0gylOFZjyzTV8YJIkaCOaFuHIFaqvdkoHaIyXI2BQqvFcKlMR+hJwv0WBKIcAgmaWMSIBJ/+sdfBk51zWftkv3vttdbvM3Pm7LX27VmE/ez3POt9n6WIwMzM6uNlRQdgZmad5cRvZlYzTvxmZjXjxG9mVjNO/GZmNbN70QHkceCBB0Z/f3/RYZiZlcqaNWueiYipzftLkfj7+/sZHBwsOgwzs1KRtGG0/S71mJnVjBO/mVnNOPGbmdWME7+ZWc048ZuZ1UwpZvWYmdXJqnVDXPTdh3hy6zYO6u3hnJNms3BeX9teP+mIX9JZku6TdK+kyyXtJWmWpNslPSLpSkl7pozBzKxMVq0b4ryV9zC0dRsBDG3dxnkr72HVuqG2vUeyxC+pD/gIMBARrwd2A04HLgQujohDgS3AGaliMDMrm4u++xDbXnhxh33bXniRi777UNveI3WNf3egR9LuwN7ARuA44Jrs/hXAwsQxmJmVxpNbt7W0fzKSJf6IGAK+APyIRsL/GbAG2BoR27OHPQGMWriStETSoKTBzZs3pwrTzKyrHNTb09L+yUhZ6tkfWADMAg4C9gFOzvv8iFgeEQMRMTB16k6tJszMKumck2bTs8duO+zr2WM3zjlpdtveI+WsnhOAxyJiM4CklcB8oFfS7tmofwbQvjMWZmYlNzx7J+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fBARHxxxF2l+9yPdSxJPvcRUZkf4HJgI/ACjYRyBnAAjbP664HvAVOKjnMXjuUR4MfAndnPV4qOczLH0XT/48CBRce5C/8mewLfBO4F1gLHFR3nLhzLm4E1wF00astHFR1njuN4M40yzt0jPhd/UMbP/TjH0vbPvVs2mJnVTB1KPWZmNoITv5lZzTjxm5nVjBO/mVnNOPGbmdWME79VmqQXs26Twz87NeuSdKyk69v8vsdK+t0R2++X9N52vofZZO1edABmiW2LRrfJTjsW+DnwPwAR8ZUCYjAblUf8VkuSTs56nK8FFo3Y/xlJfzVi+96sYRaS3pv1RL9L0jeyfe/MGrStk/Q9SdOyx78fOCv7K+MtI193RN/74f7q+2f7b5F0oaQ7JD0s6S0d+w9iteLEb1XX01Tq+RNJewFfBd4JHAVM2CdI0uuAT9FYmXsEcGZ2123AMRExD7gC+HhEPA58Bbg4IuZGxPebXu7rwLnR6K9+D3D+iPt2j4ijaXTKPB+zBFzqsarbqdQjaS7wWESsz7a/CSyZ4HWOA66OiGcAImK4l/0M4MqsEdiewGPjvYik/YDeiLg127WCRkO0YcONudYA/RPEZDYpHvGb7Wg7O34u9prg8f8A/GNEzAH+MsfjJ/J89vtFPDCzRJz4rY4eBPolHZJtv2vEfY8DRwJIOpJGC2mAm4A/lnRAdt+UbP9+wFB2e/FvXoZngX2b3zgifgZsGVG/fw9wa/PjzFJy4reqa67xL4uIX9Io7dyQndwd2av9W8AUSfcBH6JxjVMi4j7gc8Ctku4Chtvmfga4WtIadmzH/O/AHw2f3G2KaTGNK13dDcwF/rqNx2s2IXfnNDOrGY/4zcxqxonfzKxmnPjNzGrGid/MrGac+M3MasaJ38ysZpz4zcxq5v8BuvnWrscejzUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 观察一下有没有线性关系\n",
    "plt.scatter(income.Education, income.Income)\n",
    "plt.xlabel('Education')\n",
    "plt.ylabel('Income')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97418ffe",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一步: 定义预测函数 y = wx + b\n",
    "# 第二步:第一损失函数 1/2 * (y_true - y_pred)** 2\n",
    "# 第三步: 使用梯度下降更新参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "1f9c5f1f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:02:27.565035Z",
     "start_time": "2022-11-21T13:02:27.554065Z"
    }
   },
   "outputs": [],
   "source": [
    "# w在这里不能乘0.02 , 因为在pytorch中非叶子节点是不会自动求导的. \n",
    "w = torch.randn(1, requires_grad=True)\n",
    "b = torch.zeros(1, requires_grad=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "473f0655",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:02:29.798061Z",
     "start_time": "2022-11-21T13:02:29.786093Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-0.5656], requires_grad=True)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0cd309be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:37:45.932740Z",
     "start_time": "2022-11-21T12:37:45.919775Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.float32"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "90316dbc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:37:56.137437Z",
     "start_time": "2022-11-21T12:37:56.132450Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.float32"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca4cc928",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 从ndarray中快速生成tensor用torch.from_numpy(ndarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "372d96a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:40:35.873052Z",
     "start_time": "2022-11-21T12:40:35.820193Z"
    }
   },
   "outputs": [],
   "source": [
    "# 训练要求必须是二维\n",
    "X = torch.from_numpy(income.Education.values.reshape(-1, 1)).type(torch.FloatTensor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "73c2b4e6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:41:33.771141Z",
     "start_time": "2022-11-21T12:41:33.757178Z"
    }
   },
   "outputs": [],
   "source": [
    "Y = torch.from_numpy(income.Income.values).type(torch.FloatTensor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0f807a56",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:40:40.377001Z",
     "start_time": "2022-11-21T12:40:40.364035Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.float32"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e17cc8c9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T12:42:40.522542Z",
     "start_time": "2022-11-21T12:42:40.516558Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([30, 1])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce8cf94f",
   "metadata": {},
   "outputs": [],
   "source": [
    "torch.matmul()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "f71a940c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:02:36.548005Z",
     "start_time": "2022-11-21T13:02:36.530049Z"
    }
   },
   "outputs": [],
   "source": [
    "learning_rate = 0.0001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "2953ca25",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:05:35.047917Z",
     "start_time": "2022-11-21T13:04:49.258429Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([5.4691]) tensor([-37.5000]) tensor(30.0667)\n",
      "tensor([5.4693]) tensor([-37.5039]) tensor(30.0661)\n",
      "tensor([5.4695]) tensor([-37.5076]) tensor(30.0656)\n",
      "tensor([5.4697]) tensor([-37.5106]) tensor(30.0651)\n",
      "tensor([5.4698]) tensor([-37.5137]) tensor(30.0647)\n",
      "tensor([5.4700]) tensor([-37.5167]) tensor(30.0643)\n",
      "tensor([5.4702]) tensor([-37.5200]) tensor(30.0638)\n",
      "tensor([5.4703]) tensor([-37.5230]) tensor(30.0634)\n",
      "tensor([5.4705]) tensor([-37.5261]) tensor(30.0630)\n",
      "tensor([5.4707]) tensor([-37.5291]) tensor(30.0625)\n",
      "tensor([5.4708]) tensor([-37.5318]) tensor(30.0622)\n",
      "tensor([5.4709]) tensor([-37.5344]) tensor(30.0618)\n",
      "tensor([5.4711]) tensor([-37.5372]) tensor(30.0614)\n",
      "tensor([5.4712]) tensor([-37.5399]) tensor(30.0610)\n",
      "tensor([5.4714]) tensor([-37.5426]) tensor(30.0606)\n",
      "tensor([5.4716]) tensor([-37.5459]) tensor(30.0602)\n",
      "tensor([5.4717]) tensor([-37.5490]) tensor(30.0597)\n",
      "tensor([5.4719]) tensor([-37.5524]) tensor(30.0593)\n",
      "tensor([5.4721]) tensor([-37.5555]) tensor(30.0588)\n",
      "tensor([5.4722]) tensor([-37.5583]) tensor(30.0585)\n",
      "tensor([5.4724]) tensor([-37.5609]) tensor(30.0581)\n",
      "tensor([5.4725]) tensor([-37.5635]) tensor(30.0577)\n",
      "tensor([5.4726]) tensor([-37.5652]) tensor(30.0575)\n",
      "tensor([5.4727]) tensor([-37.5667]) tensor(30.0573)\n",
      "tensor([5.4728]) tensor([-37.5679]) tensor(30.0571)\n",
      "tensor([5.4728]) tensor([-37.5690]) tensor(30.0570)\n",
      "tensor([5.4729]) tensor([-37.5704]) tensor(30.0568)\n",
      "tensor([5.4730]) tensor([-37.5720]) tensor(30.0566)\n",
      "tensor([5.4730]) tensor([-37.5732]) tensor(30.0564)\n",
      "tensor([5.4731]) tensor([-37.5742]) tensor(30.0563)\n",
      "tensor([5.4731]) tensor([-37.5749]) tensor(30.0562)\n",
      "tensor([5.4732]) tensor([-37.5757]) tensor(30.0561)\n",
      "tensor([5.4732]) tensor([-37.5765]) tensor(30.0560)\n",
      "tensor([5.4733]) tensor([-37.5772]) tensor(30.0559)\n",
      "tensor([5.4733]) tensor([-37.5780]) tensor(30.0558)\n",
      "tensor([5.4733]) tensor([-37.5784]) tensor(30.0557)\n",
      "tensor([5.4733]) tensor([-37.5788]) tensor(30.0557)\n",
      "tensor([5.4734]) tensor([-37.5791]) tensor(30.0556)\n",
      "tensor([5.4734]) tensor([-37.5795]) tensor(30.0556)\n",
      "tensor([5.4734]) tensor([-37.5799]) tensor(30.0555)\n",
      "tensor([5.4734]) tensor([-37.5803]) tensor(30.0555)\n",
      "tensor([5.4734]) tensor([-37.5807]) tensor(30.0554)\n",
      "tensor([5.4735]) tensor([-37.5811]) tensor(30.0554)\n",
      "tensor([5.4735]) tensor([-37.5814]) tensor(30.0553)\n",
      "tensor([5.4735]) tensor([-37.5818]) tensor(30.0553)\n",
      "tensor([5.4735]) tensor([-37.5822]) tensor(30.0552)\n",
      "tensor([5.4735]) tensor([-37.5826]) tensor(30.0552)\n",
      "tensor([5.4736]) tensor([-37.5833]) tensor(30.0551)\n",
      "tensor([5.4736]) tensor([-37.5841]) tensor(30.0550)\n",
      "tensor([5.4737]) tensor([-37.5849]) tensor(30.0549)\n",
      "tensor([5.4737]) tensor([-37.5858]) tensor(30.0547)\n",
      "tensor([5.4738]) tensor([-37.5869]) tensor(30.0546)\n",
      "tensor([5.4738]) tensor([-37.5878]) tensor(30.0545)\n",
      "tensor([5.4739]) tensor([-37.5887]) tensor(30.0543)\n",
      "tensor([5.4739]) tensor([-37.5898]) tensor(30.0542)\n",
      "tensor([5.4740]) tensor([-37.5910]) tensor(30.0540)\n",
      "tensor([5.4741]) tensor([-37.5924]) tensor(30.0539)\n",
      "tensor([5.4742]) tensor([-37.5939]) tensor(30.0536)\n",
      "tensor([5.4742]) tensor([-37.5954]) tensor(30.0535)\n",
      "tensor([5.4743]) tensor([-37.5969]) tensor(30.0533)\n",
      "tensor([5.4744]) tensor([-37.5985]) tensor(30.0530)\n",
      "tensor([5.4745]) tensor([-37.6000]) tensor(30.0528)\n",
      "tensor([5.4746]) tensor([-37.6018]) tensor(30.0526)\n",
      "tensor([5.4747]) tensor([-37.6038]) tensor(30.0523)\n",
      "tensor([5.4748]) tensor([-37.6055]) tensor(30.0521)\n",
      "tensor([5.4749]) tensor([-37.6070]) tensor(30.0519)\n",
      "tensor([5.4750]) tensor([-37.6085]) tensor(30.0517)\n",
      "tensor([5.4750]) tensor([-37.6097]) tensor(30.0516)\n",
      "tensor([5.4751]) tensor([-37.6108]) tensor(30.0514)\n",
      "tensor([5.4751]) tensor([-37.6120]) tensor(30.0513)\n",
      "tensor([5.4752]) tensor([-37.6130]) tensor(30.0511)\n",
      "tensor([5.4752]) tensor([-37.6137]) tensor(30.0510)\n",
      "tensor([5.4753]) tensor([-37.6145]) tensor(30.0509)\n",
      "tensor([5.4753]) tensor([-37.6153]) tensor(30.0508)\n",
      "tensor([5.4754]) tensor([-37.6160]) tensor(30.0507)\n",
      "tensor([5.4754]) tensor([-37.6168]) tensor(30.0506)\n",
      "tensor([5.4754]) tensor([-37.6176]) tensor(30.0505)\n",
      "tensor([5.4755]) tensor([-37.6183]) tensor(30.0504)\n",
      "tensor([5.4755]) tensor([-37.6187]) tensor(30.0504)\n",
      "tensor([5.4755]) tensor([-37.6191]) tensor(30.0503)\n",
      "tensor([5.4755]) tensor([-37.6195]) tensor(30.0503)\n",
      "tensor([5.4756]) tensor([-37.6199]) tensor(30.0502)\n",
      "tensor([5.4756]) tensor([-37.6203]) tensor(30.0502)\n",
      "tensor([5.4756]) tensor([-37.6206]) tensor(30.0501)\n",
      "tensor([5.4756]) tensor([-37.6210]) tensor(30.0501)\n",
      "tensor([5.4756]) tensor([-37.6214]) tensor(30.0500)\n",
      "tensor([5.4757]) tensor([-37.6218]) tensor(30.0500)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n",
      "tensor([5.4757]) tensor([-37.6222]) tensor(30.0499)\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(10000):\n",
    "    for x, y in zip(X, Y):\n",
    "        y_pred = torch.matmul(x, w) + b\n",
    "        \n",
    "        # 损失函数\n",
    "        loss = (y - y_pred).pow(2).sum()\n",
    "        \n",
    "        # pytorch对同一个变量多次求导, 会把求导的结果累加起来, 需要每次循环的时候, 把导数清零. \n",
    "        if w.grad is not None:\n",
    "            # 重置w的导数\n",
    "            w.grad.data.zero_()\n",
    "            \n",
    "        if b.grad is not None:\n",
    "            b.grad.data.zero_()\n",
    "            \n",
    "        # 反向传播\n",
    "        loss.backward()\n",
    "        \n",
    "        # 更新w,b\n",
    "        # 更新的时候是不需要求导. \n",
    "        with torch.no_grad():\n",
    "            w.data -= w.grad.data * learning_rate\n",
    "            b.data -= b.grad.data * learning_rate\n",
    "    if epoch % 100 == 0:\n",
    "        y_ = torch.matmul(X, w) + b\n",
    "        l = (Y - y_).pow(2).mean()\n",
    "        print(w.data, b.data, l.data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "2a26030f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:00:46.798647Z",
     "start_time": "2022-11-21T13:00:43.539364Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "1f21d238",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:01:02.696109Z",
     "start_time": "2022-11-21T13:01:02.674168Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10.      ],\n",
       "       [10.401338],\n",
       "       [10.84281 ],\n",
       "       [11.244147],\n",
       "       [11.645485],\n",
       "       [12.086957],\n",
       "       [12.488295],\n",
       "       [12.889632],\n",
       "       [13.29097 ],\n",
       "       [13.732442],\n",
       "       [14.13378 ],\n",
       "       [14.535117],\n",
       "       [14.976588],\n",
       "       [15.377927],\n",
       "       [15.779264],\n",
       "       [16.220736],\n",
       "       [16.622074],\n",
       "       [17.02341 ],\n",
       "       [17.464884],\n",
       "       [17.86622 ],\n",
       "       [18.26756 ],\n",
       "       [18.70903 ],\n",
       "       [19.110369],\n",
       "       [19.511705],\n",
       "       [19.913044],\n",
       "       [20.354515],\n",
       "       [20.755854],\n",
       "       [21.15719 ],\n",
       "       [21.598661],\n",
       "       [22.      ]], dtype=float32)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 一个tensor可以通过.numpy获取它的ndarray形式. \n",
    "X.numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "8bb8e44a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:01:34.792233Z",
     "start_time": "2022-11-21T13:01:34.754335Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linear = LinearRegression()\n",
    "linear.fit(X.numpy(), Y.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "f4188b94",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:01:42.226344Z",
     "start_time": "2022-11-21T13:01:42.209388Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.599482], dtype=float32)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linear.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "3f0bb2ed",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:01:47.808408Z",
     "start_time": "2022-11-21T13:01:47.801426Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([5.1266])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "d54b4939",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:01:56.250819Z",
     "start_time": "2022-11-21T13:01:56.234863Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-39.44625"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linear.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "108ad442",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:02:02.270713Z",
     "start_time": "2022-11-21T13:02:02.257747Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-32.6958])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "48790878",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:06:48.901317Z",
     "start_time": "2022-11-21T13:06:48.801582Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x19c00d2e988>]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAkRklEQVR4nO3deZhU1bX38e8SUJuAtggSaOxArgIiKIQWiKAIajDqlY7mOrxGccQpCIgyeY2aEAEFEWOMogTbiwpqGDQqiIDzCDSKgOKI2jKpoKiIDOv9Y1cbaLrp6u6qOlXdv8/z8FTVqVN11gFq1a599l7b3B0REck8e0QdgIiIVI4SuIhIhlICFxHJUErgIiIZSglcRCRD1U7lwRo2bOjNmzdP5SFFRDLewoULv3D3RiW3pzSBN2/enAULFqTykCIiGc/MVpa2XV0oIiIZSglcRCRDKYGLiGQoJXARkQylBC4ikqGUwEVEMpQSuIhIhlIC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f+6KOs7KnEeJ5z8GGkYdZxX+TfYEJgNvA4uAnlHHWYVz6QYsBN4k9L12jDrOOM6jG6F75K0dPhcnZuLnfjfnkvDPvabSi4hkqEzqQhERkR0ogYuIZCglcBGRDKUELiKSoZTARUQylBK4iEiGUgIXEclQ/x/VmRnu1pYPbQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(income.Education, income.Income)\n",
    "plt.plot(X.numpy(), (torch.matmul(X, w) + b).data.numpy(), c='r')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34cb5800",
   "metadata": {},
   "source": [
    "### 简洁写法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b751fa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 简洁写法就是使用pytorch封装的api来写. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "80a042e7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:24:35.300497Z",
     "start_time": "2022-11-21T13:24:35.281548Z"
    }
   },
   "outputs": [],
   "source": [
    "from torch import nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "bc708dc2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:26:18.626041Z",
     "start_time": "2022-11-21T13:26:18.600110Z"
    }
   },
   "outputs": [],
   "source": [
    "# pytorch中的全连接, 或者说神经网络, 或者说线性运算, \n",
    "model = nn.Linear(1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "90d95be1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:27:00.745350Z",
     "start_time": "2022-11-21T13:27:00.736371Z"
    }
   },
   "outputs": [],
   "source": [
    "# mse\n",
    "loss_fn = nn.MSELoss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "ef099bc7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:27:18.947649Z",
     "start_time": "2022-11-21T13:27:18.936675Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<generator object Module.parameters at 0x0000019C00E1C948>"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 模型要更新的参数 放在parameters中.\n",
    "model.parameters()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "4e189fb7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:29:29.169228Z",
     "start_time": "2022-11-21T13:29:29.160252Z"
    }
   },
   "outputs": [],
   "source": [
    "# 优化器\n",
    "optimizer = torch.optim.SGD(model.parameters(), lr=0.001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "8f7b3893",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:32:48.361275Z",
     "start_time": "2022-11-21T13:31:45.143418Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\.venv\\lib\\site-packages\\torch\\nn\\modules\\loss.py:529: UserWarning: Using a target size (torch.Size([1])) that is different to the input size (torch.Size([])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.\n",
      "  return F.mse_loss(input, target, reduction=self.reduction)\n"
     ]
    }
   ],
   "source": [
    "# 训练\n",
    "for epoch in range(10000):\n",
    "    for x, y in zip(X, Y):\n",
    "        y_pred = model(x)\n",
    "        loss = loss_fn(y, y_pred)\n",
    "        # 梯度清零\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        # 更新参数\n",
    "        optimizer.step()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "e660bfd4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:32:48.747243Z",
     "start_time": "2022-11-21T13:32:48.734276Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "tensor([[5.1309]], requires_grad=True)"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "8737debc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-11-21T13:33:01.190455Z",
     "start_time": "2022-11-21T13:33:01.175496Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "tensor([-32.7909], requires_grad=True)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.bias"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
